<?php

use yii\helpers\Html;
use yii\grid\GridView;
use common\business\EhrHelper;
use yii\helpers\ArrayHelper;
use backend\helpers\TaskUiHelper;

/* @var $this yii\web\View */
/* @var $searchModel common\models\TaskSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Tasks');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="task-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a(Yii::t('app', 'Create Task'), ['create'], ['class' => 'btn btn-success']) ?>
        <?= Html::a(Yii::t('app', 'Execute All'), ['execute-all'], ['class' => 'btn btn-primary']) ?>
        <?= Html::a('测试主数据接口', ['/mdm/mdm/test'], ['class' => 'btn btn-primary']) ?>
    </p>
    <?php
    try {
        $gv = GridView::widget([
            'tableOptions' => ['class' => 'table table-condensed table-bordered table-striped table-hover'],
            'pager' => [
//            'class'          => GoPager::className(),
                'nextPageLabel'  => Yii::t('app', 'Next Page'),
                'prevPageLabel'  => Yii::t('app', 'Previous Page'),
                'firstPageLabel' => Yii::t('app', 'First Page'),
                'lastPageLabel'  => Yii::t('app', 'Last Page'),
                'options' => [
                    'class' => 'pagination pagination-sm m-t-none m-b-none',
                ],
            ],
            'dataProvider' => $dataProvider,
            'filterModel' => $searchModel,
            'columns' => [
                [
                    'class'         => 'yii\grid\ActionColumn',
                    'template'      => '{reset} {view} {update} {delete}',
                    'header'        => '操作',
                    'headerOptions' => ['class' => 'text-center no-margin'],
                    'buttons'       => [
//                    'execute' => function($url, $model, $key) {
//                        $options = [
//                            'title' => Yii::t('app', 'Execute'),
//                            'data-id' => $key,
//                        ];
//                        return Html::a('<span class="	glyphicon glyphicon-triangle-right edit-class"></span>', $url, $options);
//                    },
                        'reset' => function($url, $model, $key) {
                            $options = [
                                'title' => Yii::t('app', 'Reset'),
                                'data-id' => $key,
                            ];
                            return Html::a('<span class="	glyphicon glyphicon-step-forward edit-class"></span>', $url, $options);
                        },
                    ],
                ],
                [
                    'class' => 'yii\grid\SerialColumn',
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 25px;'],
                ],

//            'task_id',
                [
                    'attribute' => 'status',
                    'value' => function ($model, $key, $index, $column) {
                        return TaskUiHelper::getLabelSpanByStatus($model['status'], EhrHelper::getTaskStatusStr($model['status']));
                    },
                    'format'    => 'raw',
                    'filter' => \common\consts\Consts::TASK_STATUS_MAP(),
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                ],
                [
                    'attribute' => 'type',
                    'value' => function ($model) {
                        return EhrHelper::getTaskTypeStr($model['type']);
                    },
                    'filter' => \common\consts\Consts::TASK_TYPE_MAP(),
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 150px;'],
                ],
//            [
//                'attribute' => 'priority',
//                'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 30px;'],
//                'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 30px;'],
//            ],
//            [
//                'attribute' => 'key',
//                'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
//                'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
//            ],
                [
                    'attribute' => 'from_system',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 20px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 20px;'],
                ],
                [
                    'attribute' => 'request_data',
//                'value' => function ($model, $key, $index, $column) {
//                    return \common\helpers\StringUtil::getShortString($model['response_data'], 30);
//                },
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'white-space: normal; width: 100px;'],
//                'contentOptions' => ['style' => 'white-space: normal;', 'width' => '20%'],
                ],
                [
                    'attribute' => 'response_data',
//                'value' => function ($model, $key, $index, $column) {
//                    return \common\helpers\StringUtil::getShortString($model['response_data'], 30);
//                },
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 100px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'white-space: normal; width: 100px;'],
//                'contentOptions' => ['style' => 'white-space: normal;', 'width' => '20%'],
                ],
//             'memo',
                [
                    'attribute' => 'is_synchronization',
                    'value' => function ($model, $key, $index, $column) {
                        return EhrHelper::getYesOrNoByIntValue($model['is_synchronization']);
                    },
                    'filter' => EhrHelper::getYesOrNo_map(),
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 60px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 60px;'],
                ],
//             'suspend_times',
//             'retry_times',
                [
                    'attribute' => 'started_at',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                ],
//            [
//                'attribute' => 'stopped_at',
//                'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
//                'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
//            ],
                [
                    'attribute' => 'total_number',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 20px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 20px;'],
                ],
                [
                    'attribute' => 'finished_number',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 20px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 20px;'],
                ],
                [
                    'attribute' => 'finish_rate',
                    'value' => function ($model, $key, $index, $column) {
                        return TaskUiHelper::getLabelSpanByPercentage($model['finish_rate']);
                    },
                    'format' => 'raw',
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 20px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 20px;'],
                ],
                [
                    'label' => Yii::t('app', 'Executed Time'),
                    'value' => function($model, $key, $index, $column) {
                        return \common\helpers\DateHelper::getDiffDateStr($model['started_at'], $model['stopped_at']);
                    },
                    'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                    'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
                ],
//            [
//                'attribute' => 'next_run_date',
//                'headerOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
//                'contentOptions' => ['class' => 'vertical-middle text-center', 'style' => 'width: 80px;'],
//            ],
                // 'created_by',
                // 'created_at',
                // 'updated_by',
                // 'updated_at',


            ],
        ]);
    } catch (Exception $e) {
    }
    ?>
    <?= $gv ?>
</div>
